//
//  WYCStatus.m
//  WYCweibo
//
//  Created by 魏云超 on 15/11/23.
//  Copyright © 2015年 魏云超. All rights reserved.
//

#import "WYCStatus.h"
#import <MJExtension/MJExtension.h>
#import "WYCPhoto.h"
#import "NSDate+NJ.h"
@implementation WYCStatus

//mj_objectClassInArray
+ (instancetype)mj_objectClassInArray
{
    return @{@"pic_urls":[WYCPhoto class]};
}

-(NSString *)created_at
{
    NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
    formatter.locale = [NSLocale localeWithLocaleIdentifier:@"en_US"];
    formatter.dateFormat = @"EEE MMM dd HH:mm:ss Z yyyy";
    NSDate *createDate = [formatter dateFromString:_created_at];
    
    //非今年,今年 ,非昨天 ,昨天 ,今天 ,1分钟内 ,1小时内 ,其他小时 ,
    if ([createDate isThisYear]) {
        //是今年
        if ([createDate isToday]) {
            //今天
          NSDateComponents *comps =  [createDate deltaWithNow];
            if (comps.hour >= 1) {
                //1小时以外
                return [NSString stringWithFormat:@"%tu小时前",comps.hour];
            }else if(comps.minute>1){
                //1小时内 1分钟外
                return [NSString stringWithFormat:@"%tu分钟前",comps.minute];
            }else{
                //1分钟内
                return @"刚刚";
            }
        }else if ([createDate isYesterday]){
            //昨天
            formatter.dateFormat = @"昨天 HH时mm分";
            return [formatter stringFromDate:createDate];
        }else{
            //其他天
            formatter.dateFormat = @"MM月dd日 HH时mm分";
            return [formatter stringFromDate:createDate];
        }
    }else{
        //非今年
        formatter.dateFormat = @"YYYY年MM月dd日 HH时mm分";
        return [formatter stringFromDate:createDate];
    }

}

-(void)setSource:(NSString *)source
{
    if ([_source isEqualToString:@""] || _source == nil) {
        return;
    }
        NSRange StartRange = [_source rangeOfString:@">"];
        NSInteger startIndex = StartRange.location + 1;
    
        NSRange endRange = [_source rangeOfString:@"</"];
        NSInteger length = endRange.location -startIndex;
    
        NSRange range = NSMakeRange(startIndex, length);
    
      _source = [NSString stringWithFormat:@"来自:%@",[_source substringWithRange:range]];
}
@end
